How to Extract Public Key from .PEM file

Key.pem can contain anything - a certificate with a public key, an SSH public key, public key + private key, certificate with a public key + private key while key.pub contains public key in Open SSH format.

Below are the steps to extract the public key from .pem file to access ec2 servers.

Note: Download “Git” to extract public key(.pub) from .pem file.

Link: https://git-scm.com/downloads

  1. Access the location where the .pem file is saved.
  2. Right click on the location and click on select Git Bash Here as shown in the screenshot.

  3. Execute the below command in the console to extract public key.

    ssh-keygen -y -f private_key1.pem > public_key1.pub

    Eg. ssh-keygen -y -f jamcracker.pem > jamcracker.pub

  4. The public key will be extracted in the same location as pem file & the format of the key is ‘.pub’. Open the file with Notepad ++ or Editplus.